//
//  ByMessageVC.m
//  mijifen_ios
//
//  Created by mc on 2017/10/20.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByMessageVC.h"

// cell
#import "ByCellMessage.h"

@interface ByMessageVC ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *dataArray;
@end

@implementation ByMessageVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"消息";
    self.view.backgroundColor = BY_TABLE_COLOR;
    [self initTable];
    [self fetchData];
}
#pragma mark - 测试数据
- (void)fetchData{
    for (int i = 0; i < 10; i ++) {
        ByModelMessage *model = [[ByModelMessage alloc] init];
        model.pay_name = @"176757656576";
        model.pay_code = @"20170500231";
        model.create_time = @"05-20 10:30:23";
        model.price = @"¥ 50.0";
        model.point = @"+ 500";
        model.red_price = @"2";
        [self.dataArray addObject:model];
    }
    [self.tableView reloadData];
}
#pragma mark - getter
- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

#pragma mark -
- (void)initTable{
    _tableView = [[UITableView alloc] init];
    [self.view addSubview:_tableView];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.backgroundColor = BY_TABLE_COLOR;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        if (@available(iOS 11.0, *)) {
            make.edges.equalTo(self.view).insets(UIEdgeInsetsZero).priorityMedium();
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-49);
        }
        else{
            make.top.equalTo(self.view.mas_top);
            make.bottom.equalTo(self.view.mas_bottom).offset(- 49);
        }
    }];

}

#pragma mark - UITableViewDataSource,UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ByCellMessage *cell = [ByCellMessage cellWithTableView:tableView];
    cell.messageModel = self.dataArray[indexPath.section];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 170 + 30 + 15 + 1 + 5 + 20 + 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0001;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
